<!-- DEBUGGER -->
<style>
    <?= file_get_contents($this->css_path); ?>
</style>

<div class="gdbg">
    <button class="gdbg-toggler" title="Show Debug Bar">Debugger ▲</button>
    <div class="gdbg-container">
        <button class="gdbg-resize-handle"></button>
        <div class="gdbg-menu">
            <button data-target="#gdbg-tab-1">
                { if(count($this->messages) > 0) }
                <i>{{ count($this->messages) }}</i>
                { /if }
                Console
            </button>
            <button data-target="#gdbg-tab-2">
                { if(count($this->exceptions) > 0) }
                <i>{{ count($this->exceptions) }}</i>
                { /if }
                Exceptions
            </button>
            <button data-target="#gdbg-tab-3">Timeline</button>
            <button data-target="#gdbg-tab-4">
                <span class="gdbg-status-code gdbg-status-code-{{ $this->method_type }}">{{ $this->request_method }}</span>
                Request
            </button>
            <button data-target="#gdbg-tab-5">Headers</button>
            <button data-target="#gdbg-tab-6">
                <span class="gdbg-status-code gdbg-status-code-{{ $this->status_type }}">{{ $this->status }}</span>
                Response
            </button>
            <button data-target="#gdbg-tab-7">Session</button>
            <button data-target="#gdbg-tab-8">Cookies</button>
            <button data-target="#gdbg-tab-9">
                { if(count($this->queries) > 0) }
                <i>{{ count($this->queries) }}</i>
                { /if }
                Queries
            </button>
            <button data-target="#gdbg-tab-10">
                { if(count($this->views) > 0) }
                <i>{{ count($this->views) }}</i>
                { /if }
                Views
            </button>
            <button data-target="#gdbg-tab-11">Application</button>
            <button class="gdbg-close" title="Hide Debug Bar">▼</button>
        </div>

        <div class="gdbg-content">
            <div class="gdbg-tab" id="gdbg-tab-1">
                <table cellspacing="0" cellpadding="0">
                    { foreach($this->messages as $message) }
                    <tr class="gdbg-row-message gdbg-row-{{ $message['type'] }}">
                        <td class="gdbg-message-time">
                            {{ $message['time'] }}
                        </td>
                        <td class="gdbg-message">
                            { if($message['type'] == 'error') }🚫{ /if }
                            { if($message['type'] == 'warning') }⚠️{ /if }
                            { if($message['type'] == 'dump') }
                            <span title="Total length: {{ strlen($message['text']) }}" class="gdbg-expandable-value">{{ $message['text'] }}</span>
                            { else }
                            {{ $message['text'] }}
                            { /if }
                        </td>
                    </tr>
                    { /foreach }
                </table>
                <div class="gdbg-filter">
                    <button class="gdbg-filter-all" data-target="all">ALL</button>
                    <button class="gdbg-filter-info" data-target="gdbg-row-info">INFO</button>
                    <button class="gdbg-filter-error" data-target="gdbg-row-error">ERROR</button>
                    <button class="gdbg-filter-warning" data-target="gdbg-row-warning">WARNING</button>
                    <button class="gdbg-filter-dump" data-target="gdbg-row-dump">DUMP</button>
                </div>
            </div>

            <div class="gdbg-tab" id="gdbg-tab-2">
                <table cellspacing="0" cellpadding="0">
                    { foreach($this->exceptions as $e) }
                    <tr class="gdbg-row-error">
                        <td class="gdbg-message-time">
                            {{ $e['time'] }}
                        </td>
                        <td class="gdbg-message">
                            🚫 <strong>{{ Util::classname($e['exception']) }}</strong> on file <strong>{{ $e['exception']->getFile() }}</strong> at line <strong>{{ $e['exception']->getLine() }}.</strong>
                            <br>{{ $e['exception']->getMessage() }}<br>
                            <button class="gdbg-trace-toggle" title="Show/hide stack trace">View trace ▼</button>
                            <div class="gdbg-exception-trace">
                                {{!! nl2br($e['exception']->getTraceAsString()) !!}}
                            </div>
                        </td>
                    </tr>
                    { /foreach }
                </table>
            </div>

            <div class="gdbg-tab" id="gdbg-tab-3">
                <table cellspacing="0" cellpadding="0">
                    <tr>
                        <td class="gdbg-data-key" title="Total Request Time">
                            Request Time (100%)
                        </td>
                        <td class="gdbg-timer-progress" title="Total Request Time">
                            <div title="Total Request Time" class="gdbg-timer-bar gdbg-timer-bar-request" style="--gdbg-bar-width: 100%">
                                {{ $this->application['Request Time'] }}
                            </div>
                        </td>
                    </tr>
                    { foreach($this->timers as $name => $item) }
                    <tr>
                        <td class="gdbg-data-key" title="{{ $item['description'] }}">
                            {{ $name }} ({{ $item['size'] }})
                        </td>
                        <td class="gdbg-timer-progress" title="{{ $item['description'] }}">
                            <div title="{{ $item['description'] }}" class="gdbg-timer-bar" style="--gdbg-bar-width: {{ $item['size'] }}">
                                {{ $item['duration_string'] }}
                            </div>
                        </td>
                    </tr>
                    { /foreach }
                </table>
            </div>

            <div class="gdbg-tab" id="gdbg-tab-4">
                <table cellspacing="0" cellpadding="0">
                    { foreach($this->request as $key => $value) }
                    <tr>
                        <td class="gdbg-data-key">{{ $key }}</td>
                        <td class="gdbg-data-value">{{ $value }}</td>
                    </tr>
                    { /foreach }
                </table>
            </div>

            <div class="gdbg-tab" id="gdbg-tab-5">
                <table cellspacing="0" cellpadding="0">
                    { foreach($this->headers as $key => $value) }
                    <tr>
                        <td class="gdbg-data-key">{{ $key }}</td>
                        <td class="gdbg-data-value">{{ $value }}</td>
                    </tr>
                    { /foreach }
                </table>
            </div>

            <div class="gdbg-tab" id="gdbg-tab-6">
                <table cellspacing="0" cellpadding="0">
                    { foreach($this->response as $key => $value) }
                    <tr>
                        <td class="gdbg-data-key">{{ $key }}</td>
                        <td class="gdbg-data-value">{{ $value }}</td>
                    </tr>
                    { /foreach }
                </table>
            </div>

            <div class="gdbg-tab" id="gdbg-tab-7">
                <table cellspacing="0" cellpadding="0">
                    { foreach($this->session as $key => $value) }
                    <tr>
                        <td class="gdbg-data-key">{{ $key }}</td>
                        <td class="gdbg-data-value">
                            { if(is_object($value) || is_array($value)) }
                            <span class="gdbg-expandable-value">{{ var_dump($value) }}</span>
                            { else }
                            {{ $value }}
                            { /if }
                        </td>
                    </tr>
                    { /foreach }
                </table>
            </div>

            <div class="gdbg-tab" id="gdbg-tab-8">
                <table cellspacing="0" cellpadding="0">
                    { foreach($this->cookies as $key => $value) }
                    <tr>
                        <td class="gdbg-data-key">{{ $key }}</td>
                        <td class="gdbg-data-value">
                            { if(is_object($value) || is_array($value)) }
                            <span class="gdbg-expandable-value">{{ var_dump($value) }}</span>
                            { else }
                            {{ $value }}
                            { /if }
                        </td>
                    </tr>
                    { /foreach }
                </table>
            </div>

            <div class="gdbg-tab" id="gdbg-tab-9">
                <table cellspacing="0" cellpadding="0">
                    { foreach($this->queries as $query) }
                    <tr class="gdbg-row-dump {{ !$query['status'] ? 'gdbg-row-error' : '' }}">
                        <td class="gdbg-message-time">
                            { if($query['status']) }
                            ✅
                            { else }
                            ❌
                            { /if }
                            {{ $query['time'] }}
                        </td>
                        <td class="gdbg-message">
                            <span title="{{ $query['bindings'] }}" class="gdbg-expandable-value">{{ $query['query'] }}</span>
                        </td>
                    </tr>
                    { /foreach }
                </table>
            </div>

            <div class="gdbg-tab" id="gdbg-tab-10">
                <table cellspacing="0" cellpadding="0">
                    { foreach($this->views as $key => $view) }
                    <tr>
                        <td class="gdbg-data-key gdbg-valign">{{ $key }}</td>
                        <td class="gdbg-message">
                            {{ $view['file'] }}
                            { if(count($view['params']) > 0) }
                            <button title="Show/hide params" class="gdbg-trace-toggle gdbg-params-toggle">({{ count($view['params']) }}) ▼</button>
                            <div class="gdbg-exception-trace gdbg-params">
                                { foreach($view['params'] as $key => $param) }
                                {{ $key }} => {{ $param }}<br>
                                { /foreach }
                            </div>
                            { /if }
                        </td>
                    </tr>
                    { /foreach }
                </table>
            </div>

            <div class="gdbg-tab" id="gdbg-tab-11">
                <table cellspacing="0" cellpadding="0">
                    { foreach($this->application as $key => $value) }
                    <tr>
                        <td class="gdbg-data-key gdbg-valign">{{ $key }}</td>
                        <td class="gdbg-data-value">
                            {{ $value }}
                            { if($key == 'Route' && count($this->params) > 0) }
                            <button title="Show/hide params" class="gdbg-trace-toggle gdbg-params-toggle">({{ count($this->params) }}) ▼</button>
                            <div class="gdbg-exception-trace gdbg-params">
                                { foreach($this->params as $k => $param) }
                                {{ $k }} => {{ $param }}<br>
                                { /foreach }
                            </div>
                            { /if }
                        </td>
                    </tr>
                    { /foreach }
                </table>
            </div>
        </div>
    </div>
</div>

<script>
    <?= file_get_contents($this->js_path); ?>
</script>
<!-- ./ END OF DEBUGGER -->